"""员工详情页面"""
from page.base_page import BasePage
from selenium.webdriver.common.by import By
from os.path import join
from config.config import PROJECT_PATH

class EmployeePage(BasePage):
    url="/crm5/index.php?m=user&a=view&id=1"
    # 添加文件定位器
    add_document_locator = (By.LINK_TEXT, "添加文件")
    # 选择文件定位器
    choose_document_locator = (By.NAME, 'file[]')
    # 确定添加按钮
    btn_add_document_locator = (By.CSS_SELECTOR,
                                "#dialog-file input.btn-primary[type='submit'][value='添加']")
    #添加成功文本
    add_success_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > div.alert.alert-success')
    # 添加员工备注定位器
    add_note_locator = (By.LINK_TEXT, '添加员工备注')
    # 备注标题
    subject_locator = (By.ID, 'subject')
    # 添加备注的按钮定位器
    btn_add_note_locator = (By.CSS_SELECTOR,
                            '#dialog-log > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input.btn.btn-primary')
    #添加备注成功
    add_note_success_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > div.alert.alert-success')

    def click_add_document(self):
        """点击添加文件按钮"""
        self.driver.find_element(*self.add_document_locator).click()
    def send_document(self,choose_doc_path=join(PROJECT_PATH, 'data', 'QQ图片20220428123008.jpg')):
        """点击上传文件的方法"""
        self.driver.find_element(*self.choose_document_locator).send_keys(choose_doc_path)

    def click_btn_add(self):
        """点击保存"""
        self.driver.find_element(*self.btn_add_document_locator).click()
    def get_add_success(self):
        """获取添加成功文本"""
        return self.driver.find_element(*self.add_success_locator).text
    def add_note_btn(self):
        # 点击添加备注
        self.driver.find_element(*self.add_note_locator).click()
    def input_note(self,subject='test'):
        # 输入备注标题
        self.driver.find_element(*self.subject_locator).send_keys(subject)
    def click_save_note(self):
        # 点击保存
        self.driver.find_element(*self.btn_add_note_locator).click()
    def get_add_note_success(self):
        """获取添加成功信息"""
        return self.driver.find_element(*self.add_note_success_locator).text